<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.io.Process</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_io doc_spec_io_process_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../../'>Howl Documentation (master branch)</a></li><li>Spec</li><li>Io</li><li>Spec - howl.io.Process</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.io.process">howl.io.Process</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">run</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="o">...</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="k">with</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="o">...</span><span class="w">&#x000A;    </span><span class="o">\</span><span class="n">wait</span><span class="o">!</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="process">Process<span class="arg-list">(opts)</span></h2>&#x000A;&#x000A;<h4 id="raises-an-error-if-opts.cmd-is-missing-or-invalid">raises an error if opts.cmd is missing or invalid</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'cmd'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'cmd'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">not_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'id'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">not_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-a-process-object">returns a process object</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Process'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'true'</span></pre>&#x000A;&#x000A;<h4 id="raises-an-error-for-an-unknown-command">raises an error for an unknown command</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'howlblargh'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'howlblargh'</span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="sets-.argv-to-the-parsed-command-line">sets .argv to the parsed command line</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="s1">'echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">},</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">argv</span><span class="w">&#x000A;&#x000A;</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'echo "foo bar"'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'/bin/sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'echo "foo bar"'</span><span class="p">},</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">argv</span></pre>&#x000A;&#x000A;<h4 id="allows-specifying-a-different-shell">allows specifying a different shell</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">shell:</span><span class="w"> </span><span class="s1">'/bin/echo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'/bin/echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">},</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">argv</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="process.execute">Process.execute<span class="arg-list">(cmd, opts)</span></h2>&#x000A;&#x000A;<h4 id="----it-'executes-the-specified-command-and-return-&lt;out,-err,-process&gt;',-(done)--&gt;&#x000A;">    it 'executes the specified command and return &lt;out, err, process&gt;', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">out</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">execute</span><span class="w"> </span><span class="p">{</span><span class="s1">'sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'cat; echo foo &gt;&amp;2'</span><span class="p">},</span><span class="w"> </span><span class="ss">stdin:</span><span class="w"> </span><span class="s1">'reverb'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'reverb'</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'Process'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="p">(</span><span class="n">p</span><span class="p">)</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-&quot;executes-string-commands-using-/bin/sh-by-default&quot;,-(done)--&gt;&#x000A;">    it &quot;executes string commands using /bin/sh by default&quot;, (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">status</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">execute</span><span class="p">,</span><span class="w"> </span><span class="s1">'echo $0'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">status</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'/bin/sh\n'</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-&quot;allows-specifying-a-different-shell&quot;,-(done)--&gt;&#x000A;">    it &quot;allows specifying a different shell&quot;, (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">status</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="p">,</span><span class="w"> </span><span class="n">err</span><span class="p">,</span><span class="w"> </span><span class="n">process</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">execute</span><span class="p">,</span><span class="w"> </span><span class="s1">'blargh'</span><span class="p">,</span><span class="w"> </span><span class="ss">shell:</span><span class="w"> </span><span class="s1">'/bin/echo'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">status</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">match</span><span class="w"> </span><span class="n">out</span><span class="p">,</span><span class="w"> </span><span class="s1">'blargh'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'blargh'</span><span class="p">,</span><span class="w"> </span><span class="n">process</span><span class="p">.</span><span class="n">command_line</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'opts.working_directory-sets-the-working-working-directory',-(done)--&gt;&#x000A;">    it 'opts.working_directory sets the working working directory', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">execute</span><span class="w"> </span><span class="s1">'pwd'</span><span class="p">,</span><span class="w"> </span><span class="ss">working_directory:</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">dir</span><span class="p">.</span><span class="n">path</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="p">.</span><span class="n">stripped</span><span class="w">&#x000A;    </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'opts.env-sets-the-process-environment',-(done)--&gt;&#x000A;">    it 'opts.env sets the process environment', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">execute</span><span class="w"> </span><span class="p">{</span><span class="s1">'env'</span><span class="p">},</span><span class="w"> </span><span class="ss">env:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">foo:</span><span class="w"> </span><span class="s1">'bar'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo=bar'</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="p">.</span><span class="n">stripped</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'works-with-large-process-outputs',-(done)--&gt;&#x000A;">    it 'works with large process outputs', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">file_contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">string.rep</span><span class="w"> </span><span class="s2">"xxxxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzz\n"</span><span class="p">,</span><span class="w"> </span><span class="mi">5000</span><span class="w">&#x000A;    </span><span class="n">f</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">file_contents</span><span class="w">&#x000A;    </span><span class="n">status</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">pcall</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">execute</span><span class="p">,</span><span class="w"> </span><span class="s2">"cat </span><span class="si">#{</span><span class="n">f</span><span class="p">.</span><span class="n">path</span><span class="si">}</span><span class="s2">"</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">status</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">file_contents</span><span class="p">,</span><span class="w"> </span><span class="n">out</span><span class="w">&#x000A;    </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="pump">pump<span class="arg-list">(on_stdout, on_stderr)</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the &lt;on_stdout&gt; handler is provided)</span></h3>&#x000A;&#x000A;<h4 id="------it-'invokes-the-handler-for-any-stdout-output-before-returning',-(done)--&gt;&#x000A;">      it 'invokes the handler for any stdout output before returning', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">on_stdout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'echo foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">read_stdout:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">pump</span><span class="w"> </span><span class="n">on_stdout</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exited</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stdout</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'foo\n'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stdout</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the &lt;on_stderr&gt; handler is provided)</span></h3>&#x000A;&#x000A;<h4 id="------it-'invokes-the-handler-for-any-stderr-output-before-returning',-(done)--&gt;&#x000A;">      it 'invokes the handler for any stderr output before returning', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">on_stderr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'echo err &gt;&amp;2'</span><span class="p">,</span><span class="w"> </span><span class="ss">read_stderr:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">pump</span><span class="w"> </span><span class="kc">nil</span><span class="p">,</span><span class="w"> </span><span class="n">on_stderr</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exited</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stderr</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'err\n'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stderr</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when both handlers are provided)</span></h3>&#x000A;&#x000A;<h4 id="------it-'invokes-both-handlers-for-any-output-before-returning',-(done)--&gt;&#x000A;">      it 'invokes both handlers for any output before returning', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">on_stdout</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">on_stderr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'echo out; echo err &gt;&amp;2'</span><span class="p">,</span><span class="w"> </span><span class="ss">read_stdout:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">read_stderr:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">pump</span><span class="w"> </span><span class="n">on_stdout</span><span class="p">,</span><span class="w"> </span><span class="n">on_stderr</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exited</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stdout</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'out\n'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stdout</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stderr</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'err\n'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">on_stderr</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="wait">wait<span class="arg-list">()</span></h2>&#x000A;&#x000A;<h4 id="----it-'waits-until-the-process-is-finished',-(done)--&gt;&#x000A;">    it 'waits until the process is finished', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">settimeout</span><span class="w"> </span><span class="mi">2</span><span class="w">&#x000A;</span><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">file</span><span class="o">\</span><span class="n">delete</span><span class="o">!</span><span class="w">&#x000A;    </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s2">"sleep 1; touch '</span><span class="si">#{</span><span class="n">file</span><span class="p">.</span><span class="n">path</span><span class="si">}</span><span class="s2">'"</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;    </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;    </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">file</span><span class="p">.</span><span class="n">exists</span><span class="w">&#x000A;    </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(signal handling)</span></h3>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id="send_signal-and-.signalled">send_signal<span class="arg-list">(signal)</span> and .signalled</h3>&#x000A;&#x000A;<h4 id="------it-'sends-the-specified-signal-to-the-process',-(done)--&gt;&#x000A;">      it 'sends the specified signal to the process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'cat'</span><span class="p">,</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="mi">9</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">signalled</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="------it-'.signalled-is-false-for-a-non-signaled-process',-(done)--&gt;&#x000A;">      it '.signalled is false for a non-signaled process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'id'</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">signalled</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="------it-'.signal-holds-the-signal-used-for-terminating-the-process',-(done)--&gt;&#x000A;">      it '.signal holds the signal used for terminating the process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'cat'</span><span class="p">,</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="mi">9</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">signal</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="------it-'.signal_name-holds-the-name-of-the-signal-used-for-terminating-the-process',-(done)--&gt;&#x000A;">      it '.signal_name holds the name of the signal used for terminating the process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'cat'</span><span class="p">,</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="mi">9</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'KILL'</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">signal_name</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="------it-'signals-can-be-referred-to-by-name-as-well',-(done)--&gt;&#x000A;">      it 'signals can be referred to by name as well', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'cat'</span><span class="p">,</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="s1">'KILL'</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">signal</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".exit_status">.exit_status</h2>&#x000A;&#x000A;<h4 id="is-nil-for-a-running-process">is nil for a running process</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s2">"sleep 1; true"</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exit_status</span><span class="w">&#x000A;</span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'is-nil-for-a-signalled-process',-(done)--&gt;&#x000A;">    it 'is nil for a signalled process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'cat'</span><span class="p">,</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="mi">9</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exit_status</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'is-set-to-the-exit-status-for-a-normally-exited-process',-(done)--&gt;&#x000A;">    it 'is set to the exit status for a normally exited process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="s1">'echo foo'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exit_status</span><span class="w">&#x000A;&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="p">{</span><span class="s1">'sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'exit 1'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exit_status</span><span class="w">&#x000A;&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="p">{</span><span class="s1">'sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'exit 2'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exit_status</span><span class="w">&#x000A;&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".working_directory">.working_directory</h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when provided during launch)</span></h3>&#x000A;&#x000A;<h4 id="is-the-same-directory">is the same directory</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">cwd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="w"> </span><span class="s1">'/bin'</span><span class="w">&#x000A;</span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="p">(</span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'true'</span><span class="p">,</span><span class="w"> </span><span class="ss">working_directory:</span><span class="w"> </span><span class="n">cwd</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">cwd</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">working_directory</span></pre>&#x000A;&#x000A;<h4 id="is-always-a-file-instance">is always a File instance</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="p">(</span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'true'</span><span class="p">,</span><span class="w"> </span><span class="ss">working_directory:</span><span class="w"> </span><span class="s1">'/bin'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'File'</span><span class="p">,</span><span class="w"> </span><span class="n">typeof</span><span class="w">  </span><span class="n">p</span><span class="p">.</span><span class="n">working_directory</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when not provided)</span></h3>&#x000A;&#x000A;<h4 id="is-the-current-working-directory">is the current working directory</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="p">(</span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'true'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nc">File</span><span class="p">(</span><span class="n">glib</span><span class="p">.</span><span class="n">get_current_dir</span><span class="o">!</span><span class="p">),</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">working_directory</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".successful">.successful</h2>&#x000A;&#x000A;<h4 id="----it-'is-true-if-the-process-exited-cleanly-with-a-zero-exit-code',-(done)--&gt;&#x000A;">    it 'is true if the process exited cleanly with a zero exit code', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">run</span><span class="p">(</span><span class="s1">'id'</span><span class="p">).</span><span class="n">successful</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'is-false-if-the-process-exited-with-a-non-zero-exit-code',-(done)--&gt;&#x000A;">    it 'is false if the process exited with a non-zero exit code', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">run</span><span class="p">(</span><span class="s1">'false'</span><span class="p">).</span><span class="n">successful</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'is-false-if-the-process-exited-due-to-a-signal',-(done)--&gt;&#x000A;">    it 'is false if the process exited due to a signal', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="s1">'cat'</span><span class="p">,</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="mi">9</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">successful</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".stdout">.stdout</h2>&#x000A;&#x000A;<h4 id="----it-'allows-reading-process-output',-(done)--&gt;&#x000A;">    it 'allows reading process output', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="p">},</span><span class="w"> </span><span class="ss">read_stdout:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'one\ntwo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stdout</span><span class="o">\</span><span class="n">read</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stdout</span><span class="o">\</span><span class="n">read</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".stderr">.stderr</h2>&#x000A;&#x000A;<h4 id="----it-'allows-reading-process-error-output',-(done)--&gt;&#x000A;">    it 'allows reading process error output', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'-c'</span><span class="p">,</span><span class="w"> </span><span class="s1">'echo foo &gt;&amp;2'</span><span class="p">},</span><span class="w"> </span><span class="ss">read_stderr:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'foo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stderr</span><span class="o">\</span><span class="n">read</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".stdin">.stdin</h2>&#x000A;&#x000A;<h4 id="----it-'allows-writing-to-the-process-input',-(done)--&gt;&#x000A;">    it 'allows writing to the process input', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'cat'</span><span class="p">},</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">read_stdout:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="k">with</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stdin</span><span class="w">&#x000A;    </span><span class="o">\</span><span class="n">write</span><span class="w"> </span><span class="s1">'round-trip'</span><span class="w">&#x000A;    </span><span class="o">\</span><span class="n">close</span><span class="o">!</span><span class="w">&#x000A;&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'round-trip'</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stdout</span><span class="o">\</span><span class="n">read</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".command_line">.command_line</h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the command is specified as a string)</span></h3>&#x000A;&#x000A;<h4 id="------it-'is-the-same',-(done)--&gt;&#x000A;">      it 'is the same', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'echo command "bar"'</span><span class="p">,</span><span class="w"> </span><span class="n">run</span><span class="p">(</span><span class="s1">'echo command "bar"'</span><span class="p">).</span><span class="n">command_line</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the command is specified as a table)</span></h3>&#x000A;&#x000A;<h4 id="------it-'is-a-created-shell-command-line',-(done)--&gt;&#x000A;">      it 'is a created shell command line', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s2">"echo command 'bar zed'"</span><span class="p">,</span><span class="w"> </span><span class="n">run</span><span class="p">({</span><span class="s1">'echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'command'</span><span class="p">,</span><span class="w"> </span><span class="s1">'bar zed'</span><span class="p">}).</span><span class="n">command_line</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".exit_status_string">.exit_status_string</h2>&#x000A;&#x000A;<h4 id="----it-'provides-the-exit-code-for-a-normally-terminated-process',-(done)--&gt;&#x000A;">    it 'provides the exit code for a normally terminated process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'exited normally with code 0'</span><span class="p">,</span><span class="w"> </span><span class="n">run</span><span class="p">(</span><span class="s1">'id'</span><span class="p">).</span><span class="n">exit_status_string</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'exited normally with code 1'</span><span class="p">,</span><span class="w"> </span><span class="n">run</span><span class="p">(</span><span class="s1">'exit 1'</span><span class="p">).</span><span class="n">exit_status_string</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;&#x000A;<h4 id="----it-'provides-the-signal-name-for-a-killed-process',-(done)--&gt;&#x000A;">    it 'provides the signal name for a killed process', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'cat'</span><span class="p">},</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">read_stdout:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">send_signal</span><span class="w"> </span><span class="s1">'KILL'</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'killed by signal 9 (KILL)'</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">exit_status_string</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="process.running">Process.running</h2>&#x000A;&#x000A;<h4 id="----it-'is-a-table-of-currently-running-processes,-keyed-by-pid',-(done)--&gt;&#x000A;">    it 'is a table of currently running processes, keyed by pid', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">running</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'cat'</span><span class="p">},</span><span class="w"> </span><span class="ss">write_stdin:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{[</span><span class="n">p</span><span class="p">.</span><span class="n">pid</span><span class="p">]:</span><span class="w"> </span><span class="n">p</span><span class="p">},</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">running</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="p">.</span><span class="n">stdin</span><span class="o">\</span><span class="n">close</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="nc">Process</span><span class="p">.</span><span class="n">running</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(resource management)</span></h3>&#x000A;&#x000A;<h4 id="----it-'processes-are-collected-correctly',-(done)--&gt;&#x000A;">    it 'processes are collected correctly', (done) -&gt;&#x000A;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">howl_async</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Process</span><span class="w"> </span><span class="ss">cmd:</span><span class="w"> </span><span class="p">{</span><span class="s1">'echo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'one\ntwo'</span><span class="p">},</span><span class="w"> </span><span class="ss">read_stdout:</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="s1">'one\ntwo\n'</span><span class="p">,</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stdout</span><span class="o">\</span><span class="n">read</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="o">\</span><span class="n">wait</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">p</span><span class="p">.</span><span class="n">stdout</span><span class="o">\</span><span class="n">read</span><span class="o">!</span><span class="w">&#x000A;&#x000A;  </span><span class="n">list</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{</span><span class="n">p</span><span class="p">},</span><span class="w"> </span><span class="ss">__mode:</span><span class="w"> </span><span class="s1">'v'</span><span class="w">&#x000A;  </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;  </span><span class="n">collect_memory</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">list</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w">&#x000A;  </span><span class="n">done</span><span class="o">!</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
